package com.example.juc.until;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

//线程异步回调
public class TheadAsync {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //有返回值 异步回调
        //
        CompletableFuture<Integer> completableFuture =CompletableFuture.supplyAsync(() ->{
            System.out.println(Thread.currentThread().getName()+"supplyAsync");
            return 1024;  //成功回调
        });
        System.out.println(completableFuture.whenComplete((t,u) -> {
            System.out.println("t:"+t); //正常的返回结果
            System.out.println("u:"+u); //失败的异常信息
        }).exceptionally((e) -> {
            System.out.println(e.getMessage());
            return 404; //失败回调
        }).get());
    }
}
